<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

<script type="text/javascript">
    $(function(){
        $("#dg2").datagrid({
            url:"${pageContext.request.contextPath}/user/getUserByPage",
            title:"用户列表",
            width:600,
            pagination:true,//如果为true，则在DataGrid控件底部显示分页工具栏。默认为false
            onDblClickRow:function(rowIndex,rowData){  //双击打开修改对话框

                $("#updateUserDiv").dialog("open");
                $("#id2").val(rowData.userId);
                $("#updateUserName").val(rowData.userName);
                $("#updateUserStatus").val(rowData.userStatus);
                //
            },
            loadMsg:"拼命加载中...",// string  在从远程站点加载数据的时候显示提示消息
            toolbar:"#myToolbar",//在<div>标签上定义工具栏
            columns:[[    //表格相当于二维数组，
                //{title:"操作",checkbox:true},//添加复选框

                {title:"编号",field:"userId"},//一个{}表示一列
                {title:"电话",field:"userTelephone"},
                {title:"昵称",field:"userNickname"},
                {title:"名字",field:"userName"},
                {title:"性别",field:"userSex"},
                {title:"",field:"userAutograph"},
                {title:"省份",field:"userProvince"},
                {title:"城市",field:"userCity"},
                {title:"上师",field:"guruId"},
                {title:"状态",field:"userStatus"},
                {title:"加入时间",field:"userCreateDate"},
                {title:"头像",field:"cc",
                    formatter:function(value,rowData,rowIndex){
                        return "<img src='${pageContext.request.contextPath}/img/"+rowData.userImage+"' width=\"40\" height=\"20\">";
                    }
                },
                {title:"操作",field:"cz",
                    //value:字段值；
                    //rowData:行对象
                    //rowIndex:行号；0,1....
                    formatter:function(value,rowData,rowIndex){
                        return "<a href='javascript:void(0)'  >修改</a>";
                    }
                }
            ]]
        });
        //修改对话框
        $("#updateUserDiv").dialog({
            width:300,
            title:"修改对话框",
            height:200,
            closed:true,
            buttons:"#updateDialogBtn3"  //修改按钮
        });
    })


    /*修改的信息收集和提交*/
    function doUpdate() {
        //通过form控件的submit方法提交表单
        $("#updateForm3").form("submit",{
            url:"${pageContext.request.contextPath}/user/update",
            success:function(data){
                //alert(data);
                //data就是一个json串
                var jsObj = JSON.parse(data);
                if(jsObj.isUpdate){
                    //把修改对话框关闭掉
                    //把datagrid刷新
                    alert("修改成功");
                    $("#updateUserDiv").dialog("close");
                    $("#dg2").datagrid("reload");
                }else{
                    alert("修改失败，请确认");
                }
            }
        });
    }

</script>

<table id="dg2"></table>

<div id="updateUserDiv">
    <form id="updateForm3" method="post" enctype="multipart/form-data">
        <input type="hidden" name="userId" id="id2"/>
        用户名：<input id="updateUserName" name="userName" readonly="readonly"/><br/>

        状态：<input id="updateUserStatus" name="userStatus"/><br/>
        <!-- <input type="button" value="修改" onclick="doUpdate()"/> -->
    </form>
</div>

<div id="updateDialogBtn3"><%--对话框按钮--%>
    <a href="javascript:void(0)" onclick="doUpdate()" class="easyui-linkbutton" data-options="iconCls:'icon-edit'">修改</a>
</div>
